package com.java;

import com.java.Impl.AndExproession;
import com.java.Impl.OrExpression;
import com.java.Impl.TerminalExpression;
import com.java.it.Expression;

/**
 * Hello world!
 *
 */
public class InterpreterPatternDemo
{
    //规则：Robert和John是男性
    public static Expression getMaleExpression(){
        Expression robert=new TerminalExpression("Robert");
        Expression john=new TerminalExpression("John");
        return new OrExpression(robert,john);
    }
    //规则：Julie是一个已婚的女性
    public static Expression getMarriedWomanExpression(){
        Expression julie=new TerminalExpression("Julie");
        Expression married=new TerminalExpression("Married");
        return new AndExproession(julie,married);
    }

    public static void main( String[] args )
    {
        Expression isMale=getMaleExpression();
        Expression isMarriedWoman = getMarriedWomanExpression();
        System.out.println("John is male?"+isMale.interpret("John"));
        System.out.println("Julie is a married women?"+isMarriedWoman.interpret("Married Julie"));

    }
}
